//
//  HWConcernTool.m
//  JWC
//
//  Created by lanou on 16/4/8.
//  Copyright © 2016年 陈帅. All rights reserved.
//

#import "HWConcernTool.h"
#import "HWCategoryModel.h"
#import "MJExtension.h"
#import "HWMainModel.h"
#import "HWTakeModel.h"

@implementation HWConcernTool

/************
添加关注
http://api.budejie.com/api/api_open.php?a=category&c=subscribe

下拉刷新
http://api.budejie.com/api/api_open.php?a=list&c=subscribe&category_id=35

上拉加载
http://api.budejie.com/api/api_open.php?a=list&c=subscribe&category_id=37&page=2
 **************/

// 获取左边栏数据
- (void)getCategoryData:(void(^)(id json))block
{
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    dic[@"a"] = @"category";
    dic[@"c"] = @"subscribe";
    [HttpTool post:@"http://api.budejie.com/api/api_open.php?" parameters:dic success:^(id json) {
        NSArray *mainArray = [HWCategoryModel mj_objectArrayWithKeyValuesArray:json[@"list"]];
        block(mainArray);
    } failure:^(NSError *error) {
        NSLog(@"网络请求错误");
    }];
}

// 获取右边栏数据 用于刷新数据 无需页码参数
- (void)getMainDataWithID:(NSInteger)ID block:(void(^)(id json))block
{
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    dic[@"a"] = @"list";
    dic[@"c"] = @"subscribe";
    dic[@"category_id"] = @(ID);
    [HttpTool post:[NSString stringWithFormat:@"http://api.budejie.com/api/api_open.php?a=list&c=subscribe&category_id=%ld?", ID] parameters:nil success:^(id json) {
        NSArray *listArray = [HWMainModel mj_objectArrayWithKeyValuesArray:json[@"list"]];
        block(listArray);
    } failure:^(NSError *error) {
        NSLog(@"网络请求错误");
    }];
}

// 用于右边栏加载更多数据
- (void)getMainDataWithID:(NSInteger)ID currentPage:(NSInteger)currentPage block:(void (^)(id json))block
{
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    dic[@"a"] = @"list";
    dic[@"c"] = @"subscribe";
    dic[@"category_id"] = @(ID);
    dic[@"page"] = @(currentPage);
    
    [HttpTool post:@"http://api.budejie.com/api/api_open.php?" parameters:dic success:^(id json) {
        NSArray *moreArray = [HWMainModel mj_objectArrayWithKeyValuesArray:json[@"list"]];
        block(moreArray);
    } failure:^(NSError *error) {
        NSLog(@"网络请求错误");
    }];
}

// 订阅界面
- (void)getTakeDatablock:(void (^)(id json))block
{
    [HttpTool post:@"http://d.api.budejie.com/tag/subscribe/bs0315-iphone-4.1.json" parameters:nil success:^(id json) {
        NSArray *recArray = [HWTakeModel mj_objectArrayWithKeyValuesArray:json[@"rec_tags"]];
        block(recArray);
    } failure:^(NSError *error) {
        NSLog(@"网络请求失败");
    }];
}

@end
